package com.jn.rxjava.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.jn.rxjava.R;
import com.jn.rxjava.model.WeatherResponse;

import java.util.List;

public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.ViewHolder> {
    private List<WeatherResponse.Result.Forecast> forecastList;

    public ForecastAdapter(List<WeatherResponse.Result.Forecast> forecastList) {
        this.forecastList = forecastList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.forecast_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        WeatherResponse.Result.Forecast forecast = forecastList.get(position);
        holder.dateView.setText(forecast.getDate());
        holder.conditionView.setText(forecast.getCondition());
        holder.highTempView.setText(forecast.getHighTemperature());
        holder.lowTempView.setText(forecast.getLowTemperature());
    }

    @Override
    public int getItemCount() {
        return forecastList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView dateView;
        TextView conditionView;
        TextView highTempView;
        TextView lowTempView;

        public ViewHolder(View itemView) {
            super(itemView);
            dateView = itemView.findViewById(R.id.date);
            conditionView = itemView.findViewById(R.id.condition);
            highTempView = itemView.findViewById(R.id.highTemp);
            lowTempView = itemView.findViewById(R.id.lowTemp);
        }
    }
}